#include <bits/stdc++.h>
using namespace std;
#define lowbit(x) (x & -x)
#define int long long
#define ls(x) (lower_bound(p + 1, p + sz + 1, x) - p)
const int N = 200005;

struct node {
    int x, y, val;
    bool operator<(const node& b)
    {
        return x < b.x;
    }
} nodes[N];

struct query {
    int x, y, id, type;
    bool operator<(const query& b)
    {
        return x < b.x;
    }
} q[N * 4];

int n, m, ans[N], t[N * 5], p[N * 5], c, sz;

void update(int x, int v)
{
    while (x <= sz + 1)
        t[x] += v, x += lowbit(x);
}

int sum(int x)
{
    int a = 0;
    while (x)
        a += t[x], x -= lowbit(x);
    return a;
}

signed main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> nodes[i].x >> nodes[i].y >> nodes[i].val, nodes[i].x++, nodes[i].y++, p[++c] = nodes[i].x, p[++c] = nodes[i].y;
    for (int i = 1; i <= m; i++) {
        int x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        x1++, y1++, x2++, y2++;
        q[i * 4 - 3].x = x2, q[i * 4 - 3].y = y2, q[i * 4 - 3].id = i, q[i * 4 - 3].type = 1;
        q[i * 4 - 2].x = x1 - 1, q[i * 4 - 2].y = y2, q[i * 4 - 2].id = i, q[i * 4 - 2].type = -1;
        q[i * 4 - 1].x = x2, q[i * 4 - 1].y = y1 - 1, q[i * 4 - 1].id = i, q[i * 4 - 1].type = -1;
        q[i * 4].x = x1 - 1, q[i * 4].y = y1 - 1, q[i * 4].id = i, q[i * 4].type = 1;
        p[++c] = x1, p[++c] = x2, p[++c] = y1, p[++c] = y2, p[++c] = x1 - 1, p[++c] = x2 - 1, p[++c] = y1 - 1, p[++c] = y2 - 1;
    }
    sort(nodes + 1, nodes + n + 1);
    sort(q + 1, q + m * 4 + 1);
    sort(p + 1, p + c + 1);
    sz = unique(p + 1, p + c + 1) - p - 1;
    int now = 1;
    for (int i = 1; i <= m * 4; i++) {
        while (nodes[now].x <= q[i].x && now <= n)
            update(ls(nodes[now].y), nodes[now].val), now++;
        ans[q[i].id] += sum(ls(q[i].y)) * q[i].type;
    }
    for (int i = 1; i <= m; i++)
        cout << ans[i] << endl;
    return 0;
}